﻿<?php

/**
 * User: yangcheng
 */
header ( "Content-type:text/html;charset=utf-8" );  //统一输出编码为utf-8  
$mysql_server_name = "qdm113416174.my3w.com"; //mysql数据库服务器
$mysql_username = "qdm113416174"; //mysql数据库用户名
$mysql_password = "yang147258369"; //mysql数据库密码
$mysql_database = "qdm113416174_db"; //mysql数据【库】名
$mysql_table = "carts"; //mysql数据【表】名


/**
 * 打印函数
 */
function println($msg)
{
    echo json_encode($msg);
}

/** 新建 连接 */
$mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password);
/** 调试连接是否正常 */
//var_dump($mysqli);

/** 
 * check connection 
 */
if ($mysqli->connect_errno) {
	$code = 400;
	$msg = "Connect failed: ". $mysqli->connect_error;
	$responce->code = $code; //代码 
	$responce->msg = $msg; //信息
    println($responce);
    exit();
}else{
	$mysqli->set_charset("utf8");//设置读、写数据的编码
	del();
}


function del(){
	global $mysqli,$mysql_database,$mysql_table;
	$mysqli->select_db($mysql_database);

	
	$pid=$_GET["pid"]; //取得json数据


	//执行SQL 
	$result = $mysqli->query("SELECT * FROM $mysql_table WHERE pid = $pid");
	//返回信息
	$code = 0;
	$msg = "查询成功！";
	//是否插入成功判断
	if ($result != true) {
		$code=400;
		$msg =  "查询失败！" ;
	}else{
		$row = $result->fetch_row();
		// carts对象
		$carts = array ( 
			 "pid"  => intval($row[0]), 
			 "idcard"  => $row[1], 
			 "sys_content"  => $row[2], 
			 "sys_create_time"  => $row[3], 
			 "last_modify_time"  => $row[4]
		 );
		$responce->carts = $carts; //信息
	}

	

	$responce->code = $code; //代码 
	

	println($responce); //输出JSON数据 

}

/**
 * 关闭连接
 */
$mysqli->close();

